package cn.candy.order.controller;

import cn.candy.basic.util.AjaxResult;
import cn.candy.basic.util.PageList;
import cn.candy.order.domain.AdoptOrder;
import cn.candy.order.query.AdoptOrderQuery;
import cn.candy.order.service.IAdoptOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;


/**
 * 领养订单接口类
 */
@RestController
@RequestMapping("/adoptOrder")
@Api(tags = "领养订单接口类",description = "领养订单接口详细描述")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adoptOrderService;

    /**
     * 领养订单接口
     * @param params
     * @param request
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation(value = "领养订单接口",notes = "")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){
        try{
            String payData = adoptOrderService.adoptOrderSubmit(params, request);
            System.out.println(payData);
            //将支付数据响应给前端 - 前端可以跳转到支付页面完成支付
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg("下单失败！"+e.getMessage());
        }
    }

    /**
     * 获取管理员的领养订单
     * @param adoptOrderQuery
     * @param request
     * @return
     */
    @PostMapping("/admin")
    @ApiOperation(value = "管理员领养订单接口",notes = "")
    public PageList<AdoptOrder> adminAdoptOrder(@RequestBody AdoptOrderQuery adoptOrderQuery,
                                                HttpServletRequest request){
        return adoptOrderService.adminAdoptOrder(adoptOrderQuery,request);
    }


    /**
     * 获取用户的领养订单
     * @param adoptOrderQuery
     * @param request
     * @return
     */
    @PostMapping("/user")
    @ApiOperation(value = "用户领养订单接口",notes = "")
    public PageList<AdoptOrder> userAdoptOrder(@RequestBody AdoptOrderQuery adoptOrderQuery,
                                                HttpServletRequest request){
        return adoptOrderService.userAdoptOrder(adoptOrderQuery,request);
    }
}
